#!/usr/bin/env/python3
# -*- coding: utf-8 -*-

"""
@Time    : 2020/3/31 9:36
@Author  : Chen Liu
@FileName: max_qianzhui.py
@Software: PyCharm
"""


# 会不会存在最小值和最大值有公共前缀，而其余值不满足。--不会，主要是字符串的max,min
# 对字符串列表求最大值和最小值，会先比较第一个字母的ASCII码，然后依次比较第二个第三个，进行排序。
# 比如[a, b, ac]的最大值是b,最小值是a
def longestCommonPrefix(strs):
    """
    :type strs: List[str]
    :rtype: str
    """
    if not strs:
        return ''
    a = min(strs)
    print("a: ", a)
    b = max(strs)
    print("b: ", b)
    if a == '':
        return ''
    l = len(a) + 1
    for i in range(l):
        try:
            if a[i] == b[i]:
                continue
            else:
                break
        except:
            break
    return a[0:i]


if __name__ == "__main__":
    strs = ["a", "b", "ac", "ac"]
    res = longestCommonPrefix(strs)
    print("res: ", res)
